package com.sales.service.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.Window;

import com.sales.service.R;

/**
 * This is the opening screen of the application.
 * An image is displayed with the spinning progress bar.
 * Its is displayed for 6 seconds.
 * Android's Count down timer is used.
 * After the timer is finished the Login Activity is started.
 * 
 * @author Sega
 *
 */
public class SplashActivity extends Activity {

	/**
	 * Strings for debugging process by log.i method
	 */
	private static final String TagProject = "SalesService";
	private static final String TagPage = "Splash ::";
	
	/* (non-Javadoc)
	 * @see android.app.Activity#onCreate(android.os.Bundle)
	 * 
	 * This is the onCreate overridden method.
	 * The timer is started here.
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.splash_layout);
		Log.i(TagProject, TagPage);

		timer();
        Log.i(TagProject, TagPage + "Timer Started.");
	}
	
	/**
	 * Timer for 6 seconds is coded here.
	 */
	public void timer(){
		CountDownTimer timer = new CountDownTimer(4000, 1000) {
			
			/* (non-Javadoc)
			 * @see android.os.CountDownTimer#onTick(long)
			 * 
			 * This is the overridden method for the timer operation.
			 * For every ticking an action can be performed.
			 * We have not done any task here.
			 */
			@Override
			public void onTick(long millisUntilFinished) {
				
			}
			
			/* (non-Javadoc)
			 * @see android.os.CountDownTimer#onFinish()
			 * 
			 * This the other overridden method of timer.
			 * Only here the task after the timer finished is performed.
			 * Here The Login Activity is started.
			 */
			@Override
			public void onFinish() {
				Intent intentb = new Intent(SplashActivity.this, LoginActivity.class);
				startActivity(intentb);
			}
		};
		
		timer.start();
	}
}